package top.zhangjianyong.tools.utils;

import top.zhangjianyong.tools.entity.HasVersion;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author zhangjianyong
 * @since 2025/3/26 下午12:04
 */
public class UpdateUtil {

    public static <T extends HasVersion> boolean updateByVersion(Supplier<T> getOne, Function<T, Boolean> consumer, int count) {
        T one = getOne.get();
        Boolean apply = consumer.apply(one);
        if (apply) return true;
        if (count > 0) {
            count--;
            return updateByVersion(getOne, consumer, count);
        }
        return false;
    }
}
